package org.coody.gitee.fuzzer;

import java.text.MessageFormat;

import org.coody.gitee.entity.GiteeEntity;
import org.coody.gitee.exception.FuzzerException;
import org.coody.gitee.exception.RegisterException;
import org.coody.gitee.fuzzer.iface.GiteeFuzzer;
import org.coody.gitee.util.HttpUtil;
import org.coody.gitee.util.HttpUtil.HttpEntity;

public class GiteeRegisterFuzzer extends GiteeFuzzer {

	@Override
	public void fuzzer(GiteeEntity giteeEntity) throws FuzzerException {

		String postData = MessageFormat.format(
				"utf8=%E2%9C%93&authenticity_token={0}&user%5Bfrom%5D=register&user%5Bemail%5D={1}&captcha={2}&email_captcha={3}&user%5Bname%5D={4}&user%5Busername%5D={5}&user%5Bpassword%5D={6}&accept_term=0&button=",
				giteeEntity.getCsrfToken(), giteeEntity.getEmail(), giteeEntity.getImgCode(),
				giteeEntity.getEmailCode(), giteeEntity.getAccount(), giteeEntity.getSpace(),
				giteeEntity.getPassword());
		HttpEntity entity = HttpUtil.Post("https://gitee.com/", postData, "utf-8", giteeEntity.getCookie(),
				giteeEntity.buildHeader());
		giteeEntity.setCookie(entity.getCookie());
		if (entity.getCode() != 302) {
			throw new RegisterException("注册失败>>" + giteeEntity.getEmail() + ":" + entity.getCode());
		}
		System.out.println("注册成功>>" + giteeEntity.getEmail());
	}
}
